//
//  XKLCommentCell.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/5/9.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "XKLCommentCell.h"
#import "XKLTopCommetItem.h"
#import <UIImageView+WebCache.h>
#import "XKLUserItem.h"

@interface XKLCommentCell()
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UIImageView *sex;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *likeCount;
@property (weak, nonatomic) IBOutlet UILabel *text;

@end

@implementation XKLCommentCell

- (void)awakeFromNib {
    self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comment-bar-bg"]];
}

-(void)setItem:(XKLTopCommetItem *)item{
    _item = item;
    
    [self.icon sd_setImageWithURL:[NSURL URLWithString:item.user.profile_image] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        //开启上下文
        UIGraphicsBeginImageContextWithOptions(self.icon.frame.size, NO, [UIScreen mainScreen].scale);
        
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, self.icon.width, self.icon.height)];
        
        [path addClip];
        [image drawInRect:CGRectMake(0, 0, self.icon.width, self.icon.height)];
        self.icon.image = UIGraphicsGetImageFromCurrentImageContext();
        
        //关闭上下文
        UIGraphicsEndImageContext();
        
    }];
    self.text.text =item.content;
    self.likeCount.text = [NSString stringWithFormat:@"%ld",item.like_count];
    self.name.text = item.user.username;
    if ([item.user.sex isEqualToString:@"m"]) {
        self.sex.image =  [UIImage imageNamed:@"Profile_manIcon"];
    }else{
        
        self.sex.image =  [UIImage imageNamed:@"Profile_womanIcon"];
    }
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
